<template>
	<view class="liuyan">
		<uni-nav-bar shadow left-icon="left" @clickLeft="back" />
		<uni-section title="留言板" titleFontSize="20px" type=square>
			<view class="liuyan-box">
				<uni-forms ref="baseForm" :modelValue="baseFormData">
					<uni-forms-item labelWidth="0px">
						<uni-easyinput autoHeight type="textarea" v-model="baseFormData.liuyan"/>
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-section>
		<button type="primary" @click="submit('baseForm')">提交</button>
	</view>
</template>

<script>
	import axios from "axios"
	import Cookies from "js-cookie"
	export default {
		data() {
			return {
				baseFormData: {
					
					liuyan: '',
					
				},
			}
		},
		onLoad() {
			const username = Cookies.get('username')
			if(!username){
				uni.showToast({
					title:'请先登录',
					icon:"error",
					mask:true
				})
				setTimeout(res =>{
					uni.switchTab({
						url:'/pages/message/message'
					})
				},800)
			}
		},
		methods: {
			submit(ref) {
				this.$refs[ref].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})
				}).then(res =>{
					const username = uni.getStorageSync('userlist')[0].username
					const liuyan = this.baseFormData.liuyan
					axios.post('/api/setliuyan?username='+username+'&liuyan='+liuyan)
					.then(res =>{
						console.log(res.data);
					})
				})
				.catch(err => {
					console.log('err', err);
				})
			},
			back(){
				uni.switchTab({
					url:'/pages/message/message'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.liuyan {
		width: 100%;
		height: 100%;
		.liuyan-box{
			padding: 0 5%;
		}
	}
	button{
		width: 70%;
	}
</style>
